/**
 * task manage page logic.
 */
var __planId = null;
function loadPlan(planId) {
	$('#planViewContainer').load('/loadPlan?planId='+planId, function(){
		$('#planViewContainer').trigger('create');
	});
}

function pageinit() {
	$('#lvPlans').find('.planId').each(function(i, a) {
		var input = $(a).find("input").first();
		var planId = input.val();
		$(a).off('click').on('click', function(event) {
			__planId = planId;
			$("#planName").text("Plan: " + __planId);
			loadPlan(__planId);
			event.preventDefault();
		});
	});

	$('#addPlan').off('click').on('click', function(event) {
		$.mobile.changePage("/addPlan?a=newPlan", {
			transition : "flip",
			role : "dialog"
		});
		event.preventDefault();
	});
}

$(document).on('pageinit', function() {
	pageinit();
});